package com.jindianjichi.subject.domain.handler.subject;

import com.jindianjichi.subject.common.enums.SubjectInfoTypeEnum;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class SubjectHandlerFactory implements InitializingBean {
    @Resource
    private List<SubjectInfoHandler> list;
    private Map<SubjectInfoTypeEnum,SubjectInfoHandler> handlerMap=new HashMap<>();
    @Override
    public void afterPropertiesSet() throws Exception {
        for (SubjectInfoHandler subjectInfoHandler : list) {
            handlerMap.put(subjectInfoHandler.getHandlerType(),subjectInfoHandler);
        }
    }
    public SubjectInfoHandler getHandler(int subjectType) {
        SubjectInfoTypeEnum infoTypeEnum = SubjectInfoTypeEnum.getByCode(subjectType);
        return handlerMap.get(infoTypeEnum);
    }
}
